import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import '../../common/my_icon.dart';

class Toast {
  // 单例
  Toast._();

  Toast._internal() {
    EasyLoading.instance
      ..indicatorType = EasyLoadingIndicatorType.fadingCircle
      ..textPadding = EdgeInsets.all(1)
      ..textStyle = TextStyle(fontSize: 14, color: Colors.white)
      ..successWidget = Icon(MyIcon.success, color: Colors.white, size: 35)
      ..errorWidget = Icon(MyIcon.fail, color: Colors.white, size: 35);
  }

  factory Toast() => _instance;
  static Toast _instance = Toast._internal();

  /// 暴露的实例
  static Toast getInstance() => _instance;

  /// 轻提示
  /// #### [title] String|必填|文案
  /// #### [position] EasyLoadingToastPosition|选填|弹窗的未知|默认：居中显示
  static toast(
      {String title,
      EasyLoadingToastPosition position = EasyLoadingToastPosition.center}) {
    EasyLoading.showToast(title ?? "未知文案", toastPosition: position);
  }

  /// 操作失败提示
  /// #### [title] String|必填|文案
  static fail({String title}) {
    EasyLoading.showError(title ?? "操作失败");
  }

  /// 操作成功提示
  /// #### [title] String|选填|成功文案
  static success({String title}) {
    EasyLoading.showSuccess(title ?? "操作成功");
  }

  /// loading提示
  /// #### [title] String|必填|文案
  static loading({String title = "正在加载"}) {
    EasyLoading.show(status: title);
  }

  /// 关闭所有Toast
  static closeToast() => EasyLoading.dismiss();
}
